package xyz.zhangyi.onjava.java8.quiz.stream.quiz001;

import java.util.Objects;

public class Pair<L, R> {
    private L left;
    private R right;

    private Pair(L left, R right) {
        this.left = left;
        this.right = right;
    }

    public static <L, R> Pair of(L left, R right) {
        return new Pair(left, right);
    }

    public L left() {
        return left;
    }

    public R right() {
        return right;
    }

    @Override
    public String toString() {
        return String.format("(%s, %s)", left, right);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Pair<?, ?> pair = (Pair<?, ?>) o;
        return left.equals(pair.left) && right.equals(pair.right);
    }

    @Override
    public int hashCode() {
        return Objects.hash(left, right);
    }

    /*
    Quiz:

    Part I:
    给定两个数字列表，如何返回所有的数对呢？
    例如，给定列表[1, 2, 3]和列表[3, 4]，
    应该返回[(1, 3), (1, 4), (2, 3), (2, 4), (3, 3), (3, 4)].

    Part II:
    扩展前一个例子，只返回总和能被3整除的数对, 例如(2, 4)和(3, 3)是可以的。

    Refer to PairTest
     */
}
